#!/usr/bin/python
# coding=utf-8

"""批量打包

"""
__author__ = 'x'
__email__ = 'x@gmail.com'
VERSION = "v1.0"

import os, sys, re, time, getopt, string, datetime
import os.path 
import shutil
import glob

opts, args = getopt.getopt(sys.argv[1:], "hb:", ["help", "base="])

base_path = r'D:\wwplan\img\data'

def usage():
    print ("Usage:xbale.py [ops]")

if not opts:
#    usage()
#    sys.exit()
    pass
else:
    for op, value in opts:
#        print "op:value="+op+":"+value
        if op == "-b" or op == "--base":
            is_has_base_path = True
            base_path = value
        elif op == "-h" or op == "--help":
            usage()
            sys.exit()

def copyFiles(sourceDir,  targetDir): #把某一目录下的所有文件复制到指定目录中 
     if sourceDir.find(".svn") > 0: 
         return 
     for file in os.listdir(sourceDir): 
         sourceFile = os.path.join(sourceDir,  file) 
         targetFile = os.path.join(targetDir,  file) 
         if os.path.isfile(sourceFile): 
             if not os.path.exists(targetDir): 
                 os.makedirs(targetDir) 
             if not os.path.exists(targetFile) or(os.path.exists(targetFile) and (os.path.getsize(targetFile) != os.path.getsize(sourceFile))): 
                     open(targetFile, "wb").write(open(sourceFile, "rb").read()) 
         if os.path.isdir(sourceFile): 
             First_Directory = False 
             copyFiles(sourceFile, targetFile) 
 
def removeFileInFirstDir(targetDir):#删除一级目录下的所有文件 
    for file in os.listdir(targetDir): 
        targetFile = os.path.join(targetDir,  file) 
        if os.path.isfile(targetFile): 
            os.remove(targetFile) 
 
def coverFiles(sourceDir,  targetDir):#复制一级目录下的所有文件到指定目录 
         for file in os.listdir(sourceDir): 
             sourceFile = os.path.join(sourceDir,  file) 
             targetFile = os.path.join(targetDir,  file) 
             #cover the files 
             if os.path.isfile(sourceFile): 
                 open(targetFile,"wb").write(open(sourceFile,"rb").read()) 
 
def moveFileto(sourceDir,  targetDir):#复制指定文件到目录 
    shutil.copy(sourceDir,  targetDir) 
 
def writeVersionInfo(targetDir):#往指定目录写文本文件 
    open(targetDir, "wb").write("Revison:") 
 
def getCurTime():#返回当前的日期，以便在创建指定目录的时候用 
     nowTime = time.localtime() 
     year = str(nowTime.tm_year) 
     month = str(nowTime.tm_mon) 
     if len(month) < 2: 
         month = '0' + month 
     day =  str(nowTime.tm_yday) 
     if len(day) < 2: 
         day = '0' + day 
     return (year + '-' + month + '-' + day) 

def main():
    dirname_1 = base_path+r'\logo_ok'
    dirname_2 = base_path+r'\screenshots_ok'
    dirname_3 = base_path+r'\screenshots_src'
    removeFileInFirstDir(dirname_1)
    removeFileInFirstDir(dirname_2)
    removeFileInFirstDir(dirname_3)

if __name__ == "__main__":
  sys.exit(main())

